﻿using System.Xml.Linq;
using Maple.Weixin.MP.Helpers;

namespace Maple.Weixin.MP.Entities.Messages
{
    public sealed class ResponseMessageVideo : ResponseMessageBase
    {
        internal ResponseMessageVideo(string mediaId) : this(mediaId, false) {}

        internal ResponseMessageVideo(string mediaId, bool encrypt) : base(encrypt) {
            this.MediaId = mediaId;
        }

        public override ResponseMessageType MessageType
        {
            get { return ResponseMessageType.Video; }
        }

        private string mediaId;
        private string title;
        private string description;

        public string MediaId {
            get { return mediaId ?? ""; }
            private set { mediaId = value; }
        }

        public string Title {
            get { return title ?? ""; }
            set { title = value; }
        }

        public string Description {
            get { return description ?? ""; }
            set { description = value; }
        }

        public override XDocument ToXDocumentBase()
        {
            var document = new XDocument(
                new XElement("xml",
                             new XElement("ToUserName", new XCData(ToUserName)),
                             new XElement("FromUserName", new XCData(FromUserName)),
                             new XElement("CreateTime", WeixinHelper.GetWeixinDateTime(CreateTime)),
                             new XElement("MsgType", new XCData(MessageType.ToString().ToLower())),
                             new XElement("Video", 
                                 new XElement("MediaId", new XCData(MediaId)), 
                                 new XElement("Title", new XCData(Title)),
                                 new XElement("Description", new XCData(Description)))
                    ));
            return document;
        }
    }
}
